package org.singledog.form.builder.dataset;

import org.singledog.form.builder.configuration.DataSetConfiguration;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

public abstract class AbstractDataSet implements DataSet {

    protected String datasetDirectory() {
        return null;
    }

    protected DataSetMeta getDataSetMeta(String code) {
        StringBuilder path = new StringBuilder(DataSetConfiguration.getDatasetBaseDirectory());
        if (!StringUtils.isEmpty(datasetDirectory())) {
            path.append(datasetDirectory()).append("/");
        }

        path.append(code).append(".json");
        DataSetMeta meta = DataSetMetaReader.getDataSetMeta(path.toString());
        Assert.notNull(meta, "No dataset match code [ " + code + " ] !");
        return meta;
    }

}
